<html>
<head>
    <title>吉垚物业后台管理系统</title>
    <meta charset="utf-8">
    <link rel="shortcut icon" th:href="./images/favicon.ico" type="image/x-icon">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <!-- 引入css -->
    <link rel="stylesheet" href="./css/plugins/font-awesome-4.7.0/css/font-awesome.min.css"  media="all">
    <link rel="stylesheet" href="./lib/layui-v2.3.0/css/layui.css"  media="all">
    <link rel="stylesheet" href="./css/main.css"  media="all">
    <link rel="stylesheet" href="./lib/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="timo-layout-page">
    <div class="layui-card">
        <div class="layui-card-header timo-card-header">
            <span><i class="fa fa-bars"></i> 类型管理</span>
            <i class="layui-icon layui-icon-refresh refresh-btn"></i>
        </div>
        <div class="layui-card-body">
            <div class="layui-row timo-card-screen put-row">
<!--                <div class="pull-left layui-form-pane timo-search-box">-->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">状态</label>-->
<!--                        <div class="layui-input-block timo-search-status">-->
<!--                            <select class="timo-search-select" name="status"><option value="1">正常</option><option value="2">冻结</option></select>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">所在部门</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input class="layui-input select-tree" value="" type="text" placeholder="请选择部门" data-url="#" readonly="readonly">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">用户名</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="username" value="" placeholder="请输入用户名" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label">用户昵称</label>-->
<!--                        <div class="layui-input-block">-->
<!--                            <input type="text" name="nickname" value="" placeholder="请输入用户昵称" autocomplete="off" class="layui-input">-->
<!--                        </div>-->
<!--                    </div>-->
<!--                    <div class="layui-inline">-->
<!--                        <button class="layui-btn timo-search-btn">-->
<!--                            <i class="fa fa-search"></i>-->
<!--                        </button>-->
<!--                    </div>-->
<!--                </div>-->
                <div class="pull-right screen-btn-group">
<!--                    <div class="btn-group-left">-->
<!--                        <button class="layui-btn open-popup-param" data-title="修改密码" data-size="456,242" data-url="#">-->
<!--                            <i class="fa fa-refresh"></i> 修改密码</button>-->
<!--                        <button class="layui-btn open-popup-param" data-type="radio" data-title="角色分配" data-size="480,400" data-url="#">-->
<!--                            <i class="fa fa-user-secret"></i> 角色分配</button>-->
<!--                    </div>-->
                    <div class="btn-group-right">
                        <button class="layui-btn open-popup" data-title="添加类型" data-size="600,520" data-url="popupType.html">
                            <i class="fa fa-plus"></i>添加</button>
<!--                        <div class="btn-group">-->
<!--                            <button class="layui-btn">操作<span class="caret"></span></button>-->
<!--                            <dl class="layui-nav-child layui-anim layui-anim-upbit">-->
<!--                                <dd><a class="ajax-status" href="/user/status/ok">启用</a></dd>-->
<!--                                <dd><a class="ajax-status" href="/user/status/freezed">冻结</a></dd>-->
<!--                                <dd><a class="ajax-status" href="/user/status/delete">删除</a></dd>-->
<!--                            </dl>-->
<!--                        </div>-->
                    </div>
                </div>
            </div>
            <table class="layui-table ">
                <thead>
                <tr>
<!--                    <th class="timo-table-checkbox">-->
<!--                        <label class="timo-checkbox"><input type="checkbox">-->
<!--                            <i class="layui-icon layui-icon-ok"></i></label>-->
<!--                    </th>-->
                    <th>类型名</th>
                    <th>类别</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody id="types">
<!--                <tr>-->
<!--                    <td><label class="timo-checkbox"><input type="checkbox" value="1">-->
<!--                        <i class="layui-icon layui-icon-ok"></i></label></td>-->
<!--                    <td>战略合作</td>-->
<!--                    <td>合作</td>-->
<!--                    <td>2020-03-12</td>-->
<!--                    <td>-->
<!--                        <a class="open-popup" data-title="编辑" data-size="600,570" href="#" data-url="404.html">编辑</a>-->
<!--                        <a class="ajax-get" href="/user/status/delete?ids=1" data-msg=确认删除">删除</a>-->
<!--                    </td>-->
<!--                </tr>-->
                </tbody>
            </table>
        </div>
<!--        <a class="open-popup" data-title="编辑" data-size="600,570" href="#" data-url="belong-main.html">测试</a>-->
    </div>
<script type="text/javascript" src="./lib/layui-v2.3.0/layui.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/main.js" charset="utf-8"></script>
<script type="text/javascript" src="./js/plugins/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="./lib/zTree_v3/js/jquery.ztree.core.min.js"></script>
<script type="text/javascript" src="./js/timoTree.js"></script>
    <script src="js/checkToken.js"></script>
<script type="text/javascript">
    var local = window.localStorage;
    // 树形菜单


    getTypes();
function getTypes() {
    $('#types').empty();
    $.ajax({
        url: 'http://localhost:8081/admin/getTypes.do',
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        success: function (data) {
            checkToken(data)
            for (var i = 0; i < data.result.length; i++) {
                $('#types').append('<tr>\n' +
                    // '                    <td><label class="timo-checkbox"><input type="checkbox" value="1">\n' +
                    // '                        <i class="layui-icon layui-icon-ok"></i></label></td>\n' +
                    '                    <td>' + data.result[i]['name'] + '</td>\n' +
                    '                    <td>' + data.result[i]['belong'] + '</td>\n' +
                    '                    <td>' + data.result[i]['createtime'] + '</td>\n' +
                    '                    <td>' + data.result[i]['updatetime'] + '</td>\n' +
                    '                    <td>\n' +
                    '                        <a class="open-popup" data-title="编辑" data-size="600,570" href="#" onclick="setVal('+data.result[i]['id']+',\''+data.result[i]['name']+'\',\''+data.result[i]['belong']+'\')" data-url="popupUpdateType.html">编辑</a>\n' +
                    '                        <a href="#" onclick="delType('+data.result[i]['id']+')">删除</a>\n' +
                    '                    </td>\n' +
                    '                </tr>')
            }
        }
    })
}
    // <a class="ajax-get" href="#" onclick="delType('+data.result[i]['id']+')">

    function setVal(typeid,name,belong) {
    console.log('进入setVal')
    console.log(typeid)
    console.log(name)
    console.log(belong)
        sessionStorage.setItem('typeid',typeid);
        sessionStorage.setItem('name',name);
        sessionStorage.setItem('belong',belong);
    }

function delType(typeid){
    if (!confirm('确认删除?'))
        return;
    $.ajax({
        url:'http://localhost:8081/admin/delType.do?typeid='+typeid,
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        headers:{
            accessToken:localStorage.getItem('accessToken')
        },
        success:function (data) {
            checkToken(data)
            if (data.resMsg=='删除成功'){
                getTypes();
            }else {
                alert('删除失败');
            }
        }
    })
}
    $.fn.selectTree({
        rootTree: '全部',
        onSelected: function(treeNode){
            local.setItem('deptTitle', treeNode.name);
        }
    });
    $(function(){
        var dept = $('.select-tree');
        if(dept.attr('value').length > 0){
            dept.val(local.getItem('deptTitle'));
        }
    });
</script>
</body>
</html>